#include <iostream>
#include <fstream>
#include "RabinKarp.h"
#include <algorithm>

using namespace std;

int main() {
	string fileName;
	string word;
	cout<<"Enter word to search"<<endl;
	getline(cin, word);
	cout<<"Enter pathfile"<<endl;
	getline(cin, fileName);
	RabinKarp rKarp=RabinKarp(word);
	vector<int> matches;

	ifstream file(fileName.c_str());
        if (file.is_open())
        {
                string line;
                int beforeLength = 0;
                while ( file.good() )
                {
					getline(file, line);
					if ( line.length() > 0 ) {
						line.append("\n");
						rKarp.getNext( line, matches, beforeLength);
						beforeLength += line.length();
					}
                }
                file.close();
        } else {
                cout<<"Error file"<<endl;
				system("pause");
				return 0;
        }

		cout<<"Number of matches "<<matches.size()<<endl;

		int toShow=min(10, (int)matches.size());
		for (int i=0; i<toShow; i++) {
			cout<<matches[i]<<endl;
		}

		system("pause");
		return 0;

}